<script type="text/javascript">
$(document).ready(function() {

    var initial_width;
    $('#opconfig_table').jqGrid({
        url: '/grid_sysconfig_for_ump',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['编号', '名称', '模块', '描述', '值', '[[ "label operation"|translate ]]'],
        colModel: [{
            name: 'id',
            index: 'id',
            width: 5,
            align: 'left',
            hidden: true
        }, {
            name: 'name',
            index: 'name',
            width: 3,
            align: 'left',
            formatter: function(cell, option, row) {
                return makeEllipsis(SelfTranslate(cell.replace('.', '_')), option, 'span');
            },
            unformat:function(cell) {
                return cell;
            }
        }, {
            name: 'category',
            index: 'category',
            width: 2,
            align: 'left',
            formatter: function(cell, option, row) {
                return SelfTranslate(cell.replace('.', '_'));
            }
        }, {
            name: 'description',
            index: 'description',
            width: 8,
            align: 'left',
            formatter: function(cell, option, row) {
                return SelfTranslate(cell.replace('.', '_'));
            }
        }, {
            name: 'value_setting',
            index: 'value_setting',
            width: 2,
            align: 'left',
            formatter: function(cell, option, row) {
                var row = row2object(row, option.gid);
                if (row['name'] == 'oplog_export.interval') {
                    return parseInt(cell) /24/ 3600
                } else if (row['name'] == 'data_recover.qos_limit' && cell != '-1') {
                    return parseInt(cell) /1024 /1024
                } else {
                    return makeEllipsis(cell, option, 'span');
                }
            },
            unformat: jqUnformat,
        }, {
            name: 'operation',
            index: 'operation',
            width: 2,
            align: 'left',
            formatter: function(row, option, row) {
                var html = '';
                html += '<button title="编辑" class="btn btn-blue" onclick=opconfig_update(' + row[0] + ')>编辑</button>';
                return html;
            }
        }],
        page: 1,
        rowNum: 10,
        sortname: 'id',
        sortorder: 'desc',
        viewrecords: true,
        autowidth: true,
        beforeSelectRow:function(rowid, e) {
            if($(e.target).is('input')) {
                return true;
            }
            return false;
        },
        gridComplete: function() {
            var gridData = $(this).jqGrid('getRowData');
            jqgrid_page($(this), gridData);
            jqgrid_resize($(this));
        },
        resizeStart: function() {
            initial_width = $(this).width();
        },
        resizeStop: function() {
            $(this).width(initial_width);
            $(".ui-jqgrid-hbox").find('.ui-jqgrid-htable').width(initial_width);
        }
    });
});

function enabled_schdule(schedule_id, enabled) {
    $.post('/schedule/update', {
        'enabled': enabled,
        'id': schedule_id
    }, function(data) {
        if (data.reply.is_success) {
            $('#opconfig_table').trigger("reloadGrid")
        } else {
            error = data.reply.error;
            SelfAlert(error);
        }
    });
}
function opconfig_update(config_id) {
    angular.element("#opconfig_controller").scope().open('/opconfig_update?config_id=' + config_id);
}

</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div class="title-tag">
            <h3>配置</h3>
            <p>系统配置</p>
        </div>
        <div class="grid-tools">
            <!-- <div class="grid-search-down-arrow">
                <i class="fa fa-angle-down"></i>
            </div> -->
            <div class="grid-operate pull-left">
                <button id="opconfig_controller" ng-controller="OpconfigModalCtrl" ng-show="false"></button>
            </div>
        </div>
        <div class="grid-body" id="div_grid_sysconfig_table">
            <table id="opconfig_table"></table>
        </div>
    </div>
</div>
